#!usr/bin/env python  
# -*- coding:utf-8 -*-
""" 
@author:robot
@file: day2.py 
@version:
@time: 2023/12/20 
"""
from typing import List

nums = [-1, 0, 3, 4, 6, 10, 13, 14]

target = 13

result = 6


class Solution:
    """
    if num[m] > target:

    l         m            r
        ^
      target

    r = m  -1


    if num[m] <= target:

    l         m           r
                    ^
                  target

    l = m + 1

    """

    def search(self, nums: List[int], target: int) -> int:
        l = 0
        r = len(nums) - 1
        while l <= r:
            m = int((l + r) / 2)
            if nums[m] == target:
                return m
            if nums[m] > target:
                r = m - 1
            else:
                l = m + 1
        return -1


Solution().search(nums, target) == result
print(Solution().search(nums, target))
